import Vue from 'vue'
import Router from 'vue-router'
import loginPage from '@/page/login'
import mainPage from "../page/mainPage";
import page1 from "../page/page1";
import page2 from "../page/page2";
import page3 from "../page/page3";
import page4 from "../page/page4";
import accountList from "../components/accountList";
import newWallet from "../components/newWallet";
import importAccount from "../components/importAccount";
import unlockAccount from "../components/unlockAccount";
import exportKeystore from "../components/exportKeystore";
import newContract from "../components/newContract";
import invokingContract from "../components/invokingContract";
import contractList from "../components/contractList";
import contractInfo from "../components/contractInfo";
import paiMaiWithdraw from "../components/paiMaiWithdraw";

Vue.use(Router)

//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'HelloWorld',
    component: loginPage
  },
  {
    path: '/login',
    name: 'loginPage',
    component: loginPage
  },
  {
    path: '/mainPage',
    name: 'mainPage',
    component: mainPage,
    children: [
      {
        path: '/page1',
        name: 'Page1',
        component: page1,
        children: [
          {
          path: '/accountList',
          name: 'accountList',
          component: accountList
        },
          {
            path: '/newWallet',
            name: 'newWallet',
            component: newWallet
          },
          {
            path: '/importAccount',
            name: 'importAccount',
            component: importAccount
          },
          {
            path: '/unlockAccount',
            name: 'unlockAccount',
            component: unlockAccount
          },
          {
            path: '/exportKeystore',
            name: 'exportKeystore',
            component: exportKeystore
          },

        ]

      },
      {
        path: '/page2',
        name: 'Page2',
        component: page2
      },
      {
        path: '/page3',
        name: 'Page3',
        component: page3
      },
      {
        path: '/page4',
        name: 'Page4',
        component: page4,
        children: [
          {
            path: '/newContract',
            name: 'newContract',
            component: newContract
          },
          {
            path: '/contractList',
            name: 'contractList',
            component: contractList,
            children:[
              {
                path: '/contractInfo',
                name: 'contractInfo',
                component: contractInfo
              },
              {
                path: '/invokingContract',
                name: 'invokingContract',
                component: invokingContract
              },
              {
                path: '/paiMaiWithdraw',
                name: 'paiMaiWithdraw',
                component: paiMaiWithdraw
              },
            ]
          },
        ]
      },
    ]
  },


]          //创建一个数组，router需要通过一个数组来进行配置
const router = new Router({
  //配置路由和组件之间的应用关系
  routes,            //将routes传入router里使用
  mode: "history",    //链接地址中不再显示#号，显示方式为window.history模式
})

//将router对象传出，即可在vue实例中使用
export default router
/*export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: loginPage
    },
    {
      path: '/login',
      name: 'loginPage',
      component: loginPage
    },
    {
      path: '/test',
      name: 'testPage',
      component: testPage
    }
  ]
})*/
